#pragma once


class CInternalWindow
{
public:
	CInternalWindow(HINSTANCE hInstance)
	:m_hInstance(hInstance)
	{
		m_hInternalWnd = NULL;
		CreateInternalWnd();
	}
	
	virtual ~CInternalWindow()
	{
		if(m_hInternalWnd)
		{
			::DestroyWindow(m_hInternalWnd);
			m_hInternalWnd = NULL;
		}
	}

public:
	virtual HWND		GetInternalHwnd() const
	{
		return ::IsWindow(m_hInternalWnd)?m_hInternalWnd:NULL;
	}

protected:

	BOOL CreateInternalWnd()
	{
		if (m_hInternalWnd != NULL && ::IsWindow(m_hInternalWnd))
			return TRUE;

		const LPCTSTR szClassName = TEXT("CInternalWindow Hide Window Class");

#ifdef __Wince__
		#define CS_CLASSDC 0x0040
#endif

		WNDCLASSEX wcex;
		wcex.cbSize			= sizeof(WNDCLASSEX); 
		wcex.style			= CS_CLASSDC;
		wcex.lpfnWndProc	= WindowProc;
		wcex.cbClsExtra		= 0;
		wcex.cbWndExtra		= 0;
		wcex.hInstance		= m_hInstance;
		wcex.hIcon			= NULL;
		wcex.hCursor		= NULL;
		wcex.hbrBackground	= (HBRUSH)NULL;
		wcex.lpszMenuName	= NULL;
		wcex.lpszClassName	= szClassName;
		wcex.hIconSm		= NULL;

		ATOM atom = RegisterClassEx(&wcex);

		
		m_hInternalWnd = ::CreateWindow(
			szClassName,
  			TEXT("CInternalWindow window"),
  			WS_POPUP | WS_THICKFRAME | WS_CAPTION,
			210,
			180,
			400,
			280,
			NULL,
			NULL,
			m_hInstance,
			NULL);

		SetWindowLong(m_hInternalWnd, GWL_USERDATA, (LONG)this);
		return m_hInternalWnd != NULL;
	}

	static LRESULT CALLBACK	WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
	{
		LRESULT lResult;
		CInternalWindow * pOb = (CInternalWindow *)GetWindowLong(hWnd, GWL_USERDATA);
		if (pOb)
			lResult = pOb->HandleWindowMsg(hWnd, uMsg, wParam, lParam);
		else 
			lResult = ::DefWindowProc(hWnd, uMsg, wParam, lParam);

		return lResult;
	}


	virtual LRESULT HandleWindowMsg(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
	{
		LRESULT lResult = 0;
		lResult = ::DefWindowProc(hWnd, uMsg, wParam, lParam);
		return lResult;
	}


private:
	HINSTANCE	m_hInstance;
	HWND		m_hInternalWnd;
};









